﻿Imports DAO
Imports DTO


Public Class TheLoaiBUS

    ' ' ' ' lấy  Toàn Thể Loại để đưa lên CommoBox
    Public Function LayTheLoai() As DataTable
        Dim dt As New DataTable
        Dim theloai As New TheLoaiDAO
        dt = theloai.layTheLoai()
        Return dt
    End Function

    Public Sub ThemTheLoai(ByVal sach As TheLoaiDTO)

        Dim theloai As New TheLoaiBUS
        Dim dt As New DataTable
        dt = theloai.LayTheLoai()
        For i = 0 To dt.Rows.Count - 1
            Dim dr As DataRow = dt.Rows(i)
            If LCase(dr.Item("TenTheLoai").ToString.Trim) = LCase(sach.LayTenTheLoai.Trim) Then
                Throw New Exception("Thể Loại " & sach.LayTenTheLoai & " đã tồn tại")
            End If
        Next
        Dim s As New TheLoaiDAO
        s.ThemTheLoai(sach)
    End Sub

    Public Function LayTenTheLoai(ByVal sach As SachDTO) As DataTable
        Dim dt As New DataTable
        'Dim tl As New TheLoaiBUS

        'dt = tl.LayTenTheLoai(sach)
        Return dt
    End Function

    Public Sub XoaTheLoai(ByVal idTheLoai As TheLoaiDTO)


        Dim theloai As New TheLoaiDAO
        theloai.XoaTheLoai(idTheLoai)
    End Sub

    Public Function LayTheLoaiTheoMa(ByVal tl As TheLoaiDTO) As DataTable
        Dim dt As New DataTable
        Dim theloai As New TheLoaiDAO
        dt = theloai.layTheLoaiTheoMa(tl)
        Return dt
    End Function
End Class
